/*
 * BirdGenerator.cpp
 *
 *  Created on: Nov 15, 2012
 *      Author: lucas
 */

#include "BirdGenerator.h"
#include <cstdlib>
#include <ctime>
#include "Vector2D.h"
#include "GameSettings.h"
#include "Bird.h"
#include "RedBird.h"
#include "BlueBird.h"
#include "GreenBird.h"
#include "BirdShootingLine.h"
#include "Game.h"
BirdGenerator::BirdGenerator(Game& g) : game(g), probBird(0) {
}
#include <iostream>
void BirdGenerator::generateBird() {
	int posbsl;
	int prob;
	int probBirdType;
	birdDirections bd;
	Vector2D speed;
	Bird* bird;

	srand(time(NULL));
	prob = rand() % 1000;
	if (prob != probBird)
		probBird = prob;
	else
		return;

	//probBird = rand() % 1000;
	if (probBird < 250) {
		posbsl = rand() % bslines.size();
		bd = bslines[posbsl]->getDirection();
		switch (bd) {
		case Left:
			speed.set(- 20 - (rand() % 40), 20 + (rand() % 40));
			break;
		case Right:
			speed.set(20 + (rand() % 40), 20 + (rand() % 40));
			break;
		default:
			speed.set(20 + (rand() % 40), 20 + (rand() % 40));
			break;
		}
		probBirdType = rand() % 3;
		switch ((birdTypes)probBirdType) {
		case Red:
			bird = new RedBird(bslines[posbsl]->getX(), bslines[posbsl]->getY(), speed);
			break;
		case Blue:
			bird = new BlueBird(bslines[posbsl]->getX(), bslines[posbsl]->getY(), speed);
			break;
		case Green:
			bird = new GreenBird(bslines[posbsl]->getX(), bslines[posbsl]->getY(), speed);
			break;
		default:
			bird = new RedBird(bslines[posbsl]->getX(), bslines[posbsl]->getY(), speed);
			break;
		}
		game.addVisibleElement(bird);
	}

}

void BirdGenerator::addBirdShootingLine(BirdShootingLine* bsl) {
	bslines.push_back(bsl);
}

BirdGenerator::~BirdGenerator() {

}

